<template>
  <div class="app-container">
    <el-input v-model="filterText" placeholder="Filter keyword" style="margin-bottom:30px;" />

    <el-tree
      ref="tree2"
      :data="data2"
      :props="defaultProps"
      :filter-node-method="filterNode"
      class="filter-tree"
      default-expand-all
    />

  </div>
</template>

<script>
import subject from '@/api/edu/subject'
export default {
  data() {
    return {
      filterText: '',
      data2: [] //返回所有数据
      , 
      defaultProps: {
        children: 'children',
        label: 'title'
      }
    }
  },
  created(){
      this.getAllSubjectList()
  },
  watch: {
    filterText(val) {
      this.$refs.tree2.filter(val)
    }
  },

  methods: {
      getAllSubjectList(){
          subject.getSubjectList()
          .then(Response =>{
              this.data2=Response.data
          })
      },
    filterNode(value, data) {
      if (!value) return true
      return data.title.toLowerCase().indexOf(value.toLowerCase()) !== -1
    }
  }
}
</script>

<style lang="scss" scoped>
.app-container{
  /deep/ .el-tree-node{
    margin-bottom: 6px;
    background-color: transparent;
  }
  /deep/ .el-tree-node__content{
    align-items: center!important;
    .el-icon-caret-right{
      margin: 0;
    }
  }
}
</style>